export default function (rawData, tags, keyWords = [], verbose = false) {
  // Return an empty array while no valid params.
  if (!rawData || rawData == null || rawData.length == 0) return [];
  if (!tags || tags == null || tags.length == 0) return [];
  verbose ? console.log("flowSummary", { rawData, tags, keyWords }) : null;
  let cell = {
    total: 0,
    type: {},
    airport: {},
  };
  for (let i = 0; i < rawData.length; i++) {
    for (let j = 0; j < tags.length; j++) {
      // verbose ? console.log("flowSummary", { row: i, column: j }) : null;
      let key = {
        airport: "OTHER",
        type: "OTHER",
        point: "OTHER",
      };
      let keyArray = tags[j].split("_");
      if (keyArray.length == 3) {
        key.airport = keyArray[0];
        key.type = keyArray[1];
        key.point = keyArray[2];
      }
      let value = rawData[i][j];

      // match keyWords
      if (
        keyWords.length > 0 &&
        !(keyWords.includes(key.airport) && keyWords.includes(key.type))
      ) {
        continue; // skip
      }
      verbose
        ? console.log("flowSummary", { row: i, column: j, key, value })
        : null;
      cell.total += value;
      // airports
      if (!cell.airport[key.airport]) {
        cell.airport[key.airport] = { total: value, type: {} };
      } else {
        cell.airport[key.airport].total += value;
      }
      // airports.types
      if (!cell.airport[key.airport].type[key.type]) {
        cell.airport[key.airport].type[key.type] = value;
      } else {
        cell.airport[key.airport].type[key.type] += value;
      }
      // types
      if (!cell.type[key.type]) {
        cell.type[key.type] = { total: value, airport: {} };
      } else {
        cell.type[key.type].total += value;
      }
      // types.airports
      if (!cell.type[key.type].airport[key.airport]) {
        cell.type[key.type].airport[key.airport] = value;
      } else {
        cell.type[key.type].airport[key.airport] += value;
      }
    }
  }
  return cell;
}
